package com.yhd.appapi.controller;

import com.github.pagehelper.Page;
import com.yhd.appapi.model.MenuDto;
import com.yhd.controller.BaseController;
import com.yhd.entity.Menu;


import com.yhd.appapi.model.MenuMsgDto;

import com.yhd.appapi.service.MenuService;
import com.yhd.model.PageInfo;
import com.yhd.model.ResultDto;
import com.yhd.model.ResultPage;
import com.yhd.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping
@Api(value = "test", description = "test")
public class TestController extends BaseController {

    @Autowired
    private MenuService menuService;

    @PostMapping("list")
    public ResultDto getMenu(){
        Menu menu=new Menu();
        menu.setId(5);
        menu=menuService.selectOne(menu);
        MenuMsgDto menuMsgDto=new MenuMsgDto();
        menuMsgDto.setName(menu.getMenuName());
        menuMsgDto.setUrl(menu.getMenuUrl());
        return success(menuMsgDto);
    }

    /**
     * 分页
     * @param pageInfo
     * @return
     */
    @ApiOperation(value = "分页任务列表", httpMethod = "POST", notes = "分页任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageInfo", value = "分页请求实体", paramType = "body", required = true, dataType = "PageInfo"),
    })
    @PostMapping("page")
    public ResultDto getPage(@RequestBody PageInfo pageInfo){
        Page<Menu> page=menuService.selectByPage(null,pageInfo);
        ResultPage<Menu> resultPage= BaseService.pageTransform(page);
        MenuDto menuDto=new MenuDto();
        menuDto.setArr(resultPage.getData());
        menuDto.setCount(resultPage.getTotal());
        return success(menuDto);
    }


}
